package com.car.slave.im.model.command;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.car.slave.im.model.IMMessage;
import com.car.slave.im.util.IMTool;

public class IMLoginMessage extends IMCommandMessage {
	
	public String uin;				// 用户唯一ID
	public String token;			// 用于校验用户的合法性
	public int clientType;			// 手机类型 1表示ios，2表示Android
	public String clientId;			// 手机唯一表示符
	public String nick;
	public String pic;
	public String address;
	public String clientVer;
	public String channel;
	
	public IMLoginMessage(String uin, String token, String clientId, String nick, String pic, 
			String address, String clientVer, String channel) {
		super();
		this.uin = uin;
		this.token = token;
		this.clientType = 2;
		this.clientId = clientId;
		this.nick = nick;
		this.pic = pic;
		this.address = address;
		this.clientVer = clientVer;
		this.channel = channel;
	}

	@Override
	public byte[] getSendBuffer() {
		Map<String, String> jsonMap = new HashMap<String, String>();
		jsonMap.put("uin", uin);
		jsonMap.put("nick", nick);
		jsonMap.put("pic", pic);
		jsonMap.put("address", address);
		jsonMap.put("token", token);
		jsonMap.put("client_type", String.valueOf(clientType));
		jsonMap.put("client_id", clientId);
		jsonMap.put("client_ver", clientVer);
		jsonMap.put("channel",channel);

		return IMTool.getIoBuffer(IMMessage.CMD_USER_LOGIN,  new JSONObject(jsonMap).toString());
	}
}
